package com.food.eat.redrain;

import com.food.eat.util.RedisOperator;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;

/**
 * 红包初始化推送类
 */

@Component
public class MoneyPush {

    @Resource
    private RedisOperator redisOperator;

    @Resource
    private RedisTemplate redisTemplate;


    /**
     * 周期为30s,进行触发红包初始化（重新发红包）
     */
    @Scheduled(cron = "0/30 * * * * ?")
    public void pushMoney() {

        // 1：查询红包策略数据，每次查询一条

        //2: 通过边缘算法将，查询到的红包金额进行随机分成多少份

        List<Double> doubleList = Arrays.asList(10.0, 15.0, 1.0, 30.0);

        Double[] moneys = new Double[doubleList.size()];


        doubleList.toArray(moneys);

        //3:数据结构转换 缓存到redis
        redisTemplate.boundListOps("1111").leftPushAll(doubleList);
//        redisOperator.leftPushAll(doubleList);


    }

}
